--花式回旋
local huashihuixuan = fk.CreateSkill {
    name = "mcdh_huashihuixuan",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

huashihuixuan:addEffect('active',{
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name) == 0
    end,
    card_filter = function() return false end,
    target_filter = function(self, player,to_select, selected, selected_cards)
        local target = to_select
        return #selected == 0 and to_select ~= player and not target:isKongcheng()
    end,
    on_use = function(self, room, effect)
        local target = effect.tos[1]
        local player = effect.from
        local  card = room:askForCardsChosen(player, target,1, 1, "h", self.name, "#huashihuixuan-discard:"..target.id)
        room:throwCard(card, self.name, target, player)
        local usecard = Fk:cloneCard("slash")
        local use = {
            from = target,
            tos = {player},
            card = usecard,
        }
        room:useCard(use)
    end
})

huashihuixuan:addEffect(fk.TurnEnd,{
    can_trigger = function(self, event, target, player, data)
        if  player:hasSkill(self) then
            local room = player.room
            local targets = {}
            local events = room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
                local use = e.data
                if use.card.is_damage_card  then
                    for _, p in ipairs(use:getAllTargets()) do
                        table.insertIfNeed(targets, p)
                    end
                end
            end, Player.HistoryTurn)
            return  table.contains(targets, player)
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        return room:askForSkillInvoke(player, self.name, nil, "#huashihuixuan_trigger-draw")
    end,
    on_use = function(self, event, target, player, data)
        player:drawCards(1,self.name)
    end
})

Fk:loadTranslationTable {
    ["mcdh_huashihuixuan"] = "花式回旋",
    [":mcdh_huashihuixuan"] = "『花式回旋』<br>出牌阶段限一次，你可以弃置一名其他角色的一张手牌，令其视为对你使用一张无距离限制的【杀】。每回合结束时，若你本回合成为过伤害牌的目标，你可以摸一张牌。",
    ["#huashihuixuan-discard"] = "花式回旋：弃置 %src 的一张手牌",
    ["#huashihuixuan_trigger-draw"] = "花式回旋：你可以摸一张牌。"
}

return huashihuixuan